--[[--
类名: TriggerAuto.lua
创建日期: 2015-3-23
创建人: 陈小虎
功能描述: 进入屏幕触发，到屏幕之外退出触发
修改内容：
修改日期:   
修改人:     
修改备注: 
]]

local Trigger = require("app.utils.trigger.Trigger")--import(".Trigger")

local TriggerAuto = class("TriggerAuto",Trigger)

function TriggerAuto:ctor()

    self.mTriggerX = 0
    self.mCameraX = 0
    
    self.mState = TriggerAuto.STATE_ENTER

    self:scheduleUpdate( handler(self, self.updateFrame))
    
end

function TriggerAuto:updateFrame(dt)
    --print("TriggerAuto:updateFrame(dt)  self.mCameraX = ",self.mCameraX)
    
    if self.mTriggerX >= self.mCameraX and self.mTriggerX <= self.mCameraX + display.width then
        --在触发区间
        if self.mState == Trigger.STATE_ENTER then
            self.mState = Trigger.STATE_IN
            self.mOnEnterDelegate()
        elseif self.mState == Trigger.STATE_IN then
            self.mOnIntervalDelegate()
        end
    else
        --不在触发区间
        if self.mState == Trigger.STATE_IN then
            self.mState = Trigger.STATE_ENTER
            self.mOnExitDelegate()
        end
    end
end

function TriggerAuto:setTriggerX(x)
    self.mTriggerX = x
    
    local line = cc.DrawNode:create()
    line:drawSegment(cc.vec3(x,0,0), cc.vec3(x,display.height,0), 1, cc.c4f(0.0, 1.0, 0.0, 1.0))
    self:addChild(line)
end

function TriggerAuto:setCameraX(cameraX)
    self.mCameraX = cameraX
end

return TriggerAuto